Skip to content

Feat: Added extra argument and test for the save option for text files - #9142

Merged
limzykenneth merged 10 commits into
processing:mainfrom
Pranava-Pai-N:feat/save-clrf
Sep 20, 2026
Merged

limzykenneth merged 10 commits into
processing:mainfrom
Pranava-Pai-N:feat/save-clrf

Conversation

@Pranava-Pai-N

Copy link
Copy Markdown
Contributor

Resolves #9141

Changes:
Added third argument for saving txt files along with the required tests

PR Checklist

  • npm run lint passes
  • [Inline reference] is included / updated
  • [Unit tests] are included / updated

@perminder-17 perminder-17 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for contributing!

Could you please provide a little more context about the issue? I just came across it, but I’m not fully clear on what was missing and how this PR fixes the issue.

@Pranava-Pai-N

Pranava-Pai-N commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @perminder-17 , thank you for the review and the doubt regarding the PR :
This PR fixes a bug where the optional CRLF flag was being dropped when saving text files through save(). The issue was that save() passed only three arguments to saveStrings(), so true for Windows-style \r\n line endings never reached the actual writer. The fix forwards the missing fourth argument, so text files can correctly preserve CRLF when requested.

The main consequence is that text files saved via save() would always use \n line endings, even when the caller explicitly asked for CRLF (true). That can cause Windows-style line-ending expectations to fail, especially when files are opened or processed by tools that rely on \r\n for compatibility.

Comment thread src/io/files.js Outdated
return;
case 'txt':
fn.saveStrings(args[0], args[1], args[2]);
fn.saveStrings(args[0], args[1], args[2], args[3]); // Takes the third argument

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the comment here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@limzykenneth Thank you for the feedback, removed the comment

Comment thread src/io/files.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it also apply here as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have updated the argument list with the required unit tests

@Pranava-Pai-N

Copy link
Copy Markdown
Contributor Author

@limzykenneth Thank you for the feedback and the questions asked. I have fixed the comment line and also added the third argument for the default case with the required tests. If any other changes, do reach out to me, would be happy to fix it or clarify any queries.
Thank you for the feedback

Comment thread src/io/files.js Outdated
default:
if (args[0] instanceof Array) {
fn.saveStrings(args[0], args[1], args[2]);
fn.saveStrings(args[0], args[1], args[2], args[3]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looked into it a bit more, the save() function itself is not meant to have 4 arguments, which means args[3] should never be a thing. The way it works is by detecting the file extension being txt and passing it to saveStrings(). ie. this is a call arguments positional issue rather than adding another argument to the call, if that made sense.

@limzykenneth limzykenneth Sep 19, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pranava-Pai-N

Copy link
Copy Markdown
Contributor Author

@limzykenneth Thanks for the clarification. After reading the docs found out that save is not meant to take the 4th parameter, but the clrf flag is passed as the third argument. I have updated the text-file dispatch to pass args[2] through to saveStrings() as the isCRLF flag, and adjusted the regression test to match the documented API shape. I also confirmed that the array fallback path was using the same issue pattern, so it now follows the same contract as the explicit .txt case.
Thanks for the clarification. open to any suggestions or feedback

@p5-bot

p5-bot Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Continuous Release

CDN link

Published Packages

Commit hash: f2617d2

Previous deployments

3474203


This is an automated message.

@limzykenneth
limzykenneth merged commit d852c3b into processing:main Sep 20, 2026
4 checks passed
@limzykenneth

Copy link
Copy Markdown
Member

Looks good. Thanks!

@Pranava-Pai-N

Copy link
Copy Markdown
Contributor Author

@limzykenneth Thanks for the merge and helpful feedback! Excited to contribute more to this project soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[p5.js 2.0+ Bug Report]: save() ignores the CRLF option when saving text files

3 participants